﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

public partial class DeliverGoodsManagement_Invoices : System.Web.UI.Page,ICallbackEventHandler
{
    public event RepeaterCommandEventHandler ItemCommand;

    #region 属性


    private bool IsUseColorSize
    {
        get
        {
            return new BLL.SYSPARAM().GetProductUpDownColorSizeConfig();
        }
    }

    private bool SelectProductConfig
    {
        get
        {
            return new BLL.SYSPARAM().GetSelectProductConfig();
        }
    }

    
    public string LockFlag
    {
        set { ViewState["lockflag"] = value; }
        get 
        {
            if (ViewState["lockflag"] != null)
            {
                return ViewState["lockflag"].ToString();
            }
            else
            {
                return "0";
            }
        }
    }
    public List<string> Selected
    {
        get
        {
            List<string> l = new List<string>();
            hdOrders.Value = "";
            foreach (RepeaterItem item in rptOrderList.Items)
            {
                CheckBox cb = item.FindControl("chkChoose") as CheckBox;
                if (cb != null && cb.Checked)
                {
                    HiddenField fld = item.FindControl("hfOrderId") as HiddenField;
                    if (fld != null)
                    {
                        string id = fld.Value;
                        l.Add(id);
                        hdOrders.Value = hdOrders.Value + fld.Value + ",";
                    }
                }
            }
            return l;
        }
    }

    private string DealType
    {
        get
        {
            string dealType = "";
            if (ViewState["DealType"] != null)
            {
                dealType = ViewState["DealType"].ToString();
            }
            return dealType;
        }
        set
        {
            ViewState["DealType"] = value;
        }
    }

    private DataSet DstOrders
    {
        get
        {
            DataSet dst = null;
            if (ViewState["DstOrders"] != null)
            {
                dst = (DataSet)ViewState["DstOrders"];
            }
            return dst;
        }
        set
        {
            ViewState["DstOrders"] = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("500100");
        Session["FCode"] = "500100";

        if (!IsPostBack)
        {
            lockunlockSataus();
            BindSort();
            btnDeliver.Attributes.Add("onclick", "Mask();");
            //txtOrderId.Attributes.Add("onkeydown", "SubmitKeyClick();"); 
            AspNetPager1.PageSize = 50;
            ORDER_OFCODE();
            BindDropOrderSuggestion();
            BindTraner();
            ReadCookie();
            Bind();

        }
    }
    #region 排序条件初始化

    void BindSort()
    {
        ddlSort.Items.Clear();
        ddlSortDrect.Items.Clear();
        ddlSort.Items.Add(new ListItem("按制单日期", "ORDER_CREATEDATE"));
        ddlSort.Items.Add(new ListItem("按发货日期", "ORDER_SENDDATE"));
        ddlSort.Items.Add(new ListItem("按审核日期", "ORDER_CHECKDATE"));
        ddlSort.Items.Add(new ListItem("按财务审核日期", "ORDER_ACHECKDATE"));
        ddlSort.SelectedIndex = 0;
        ddlSortDrect.Items.Add(new ListItem("升序", "asc"));
        ddlSortDrect.Items.Add(new ListItem("降序", "desc"));
        ddlSortDrect.SelectedIndex = 0;
    }
    #endregion

    #region 物流初始化

    private void BindTraner()
    {
        List<Model.TRANER> traners = new BLL.TRANER().GetAllList();
        dropTraner.DataSource = traners;
        dropTraner.DataTextField = "TRANER_NAME";
        dropTraner.DataValueField = "TRANER_CODE";
        dropTraner.DataBind();
        ListItem li = new ListItem();
        li.Text = "全部";
        li.Value = "-1";
        dropTraner.Items.Insert(0, li);


        dropExpressBill.DataSource = new BLL.ExpressBillTemplate().GetTranerAndExpressBillTemplate();
        dropExpressBill.DataTextField = "TranerTemplateName";
        dropExpressBill.DataValueField = "TranerTemplateId";
        dropExpressBill.DataBind();
        ListItem item = new ListItem();
        item.Text = "      ";
        item.Value = "-1";
        dropExpressBill.Items.Insert(0, item);
    }
    #endregion

    #region 订单来源
    private void ORDER_OFCODE()
    {
        List<Model.ORDERFROM> properties = new BLL.ORDERFROM().GetAllList();
        dropOrderSource.DataSource = properties;
        dropOrderSource.DataTextField = "OF_NAME";
        dropOrderSource.DataValueField = "OF_CODE";
        dropOrderSource.DataBind();
        ListItem li = new ListItem();
        li.Text = "全部";
        li.Value = "-1";
        dropOrderSource.Items.Insert(0, li);
    }
    #endregion

    #region 订单意见
    private void BindDropOrderSuggestion()
    {
        dropOrderSuggestion.DataSource = new BLL.STATETYPE().GetAllList();
        dropOrderSuggestion.DataTextField = "ST_NAME";
        dropOrderSuggestion.DataValueField = "ST_CODE";
        dropOrderSuggestion.DataBind();

        ListItem li = new ListItem();
        li.Text = "全部";
        li.Value = "-1";
        dropOrderSuggestion.Items.Insert(0, li);
    }
    #endregion

    #region 查询
    private void Bind()
    {
        //StringBuilder TableName = new StringBuilder(); //表名
        //StringBuilder FieldName = new StringBuilder();//查询字段
        //TableName.Append("OrderDoc left join V_Customer on OrderDoc.ORDER_CUSTOMERCODE = V_Customer.DM ");
        //TableName.Append("left join ORDERFROM on OrderDoc.ORDER_OFCODE = ORDERFROM.OF_CODE ");
        //TableName.Append("left join DEALTYPE on OrderDoc.ORDER_DTCODE = DEALTYPE.DT_CODE ");
        //TableName.Append("left join TRANER  on OrderDoc.ORDER_TRANERCODE =  TRANER.TRANER_CODE ");
        //TableName.Append("left join ORDERDETAIL on OrderDoc.ORDER_ID = ORDERDETAIL.OD_ID ");

        //FieldName.Append(" ORDER_ID,ORDER_SEND,ORDER_DELETE,ORDER_CLEAR,ORDER_QTY,ORDER_AAMT,ORDER_CREATEDATE,ORDER_CUSTOMERCODE,V_Customer.GKMC,ORDERFROM.OF_NAME,");
        //FieldName.Append("DEALTYPE.DT_NAME,TRANER.TRANER_NAME,ORDER_PRINT,ORDER_TPRINT,ORDER_SECDEAL,ORDER_TRANBILLCODE,ORDER_GETER , V_Customer.BYZD5 ,Order_SendDate,Order_CheckDate,ORDER_ACHECKDATE");


        string sqlstr = "";
        sqlstr += hdPCH.Value == "-1" ? "" : " and BYZD21='" + hdPCH.Value + "' ";
        sqlstr += txtOrderId.Text.Trim() == "" ? "" : " and order_id LIKE '%" + txtOrderId.Text.Trim() + "%' ";
        sqlstr += txtCustomerId.Text.Trim() == "" ? "" : " and order_customercode like '%" + txtCustomerId.Text.Trim() + "%' ";
        sqlstr += txtNickName.Text.Trim() == "" ? "" : " and V_Customer.byzd5 like '%" + txtNickName.Text.Trim() + "%' ";
        sqlstr += txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ";
        sqlstr += txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + DateTime.Parse(txtOrderEndDate.Text.Trim()).AddDays(1).ToString() + "' ";
        sqlstr += dropOrderSource.SelectedValue.Trim() == "-1" ? "" : " and ORDER_OFCODE='" + dropOrderSource.SelectedValue + "' ";
        sqlstr += dropDealType.SelectedValue.Trim() == "-1" ? "" : " and ORDER_APAY='" + dropDealType.SelectedValue + "' ";
        sqlstr += dropDelete.SelectedValue == "-1" ? "" : " and ORDER_DELETE=" + Int32.Parse(dropDelete.SelectedValue) + " ";
        sqlstr += dropDeliver.SelectedValue == "-1" ? "" : " and ORDER_SEND=" + Int32.Parse(dropDeliver.SelectedValue) + " ";
        sqlstr += dropClear.SelectedValue == "-1" ? "" : " and ORDER_Clear=" + Int32.Parse(dropClear.SelectedValue) + " ";
        sqlstr += dropTraner.SelectedValue == "-1" ? "" : " and ORDER_TRANERCODE='" + dropTraner.SelectedValue + "' ";
        sqlstr += dropExpressPrint.SelectedValue == "-1" ? "" : "and ORDER_TPRINT='" + dropExpressPrint.SelectedValue + "' ";
        sqlstr += dropDeliverPrint.SelectedValue == "-1" ? "" : "and ORDER_PRINT='" + dropDeliverPrint.SelectedValue + "' ";

        if (ddlcusprint.SelectedIndex > 0)
        {
            if (ddlcusprint.SelectedValue == "0")
            {
                sqlstr += " and ( OrderDoc.BYZD14=0 or OrderDoc.BYZD14 is null)";
            }
            else
            {
                sqlstr += " and OrderDoc.BYZD14=1";
            }
        }


        sqlstr += dropAssureDeal.SelectedValue == "-1" ? "" : " and ORDER_SECDEAL=" + dropAssureDeal.SelectedValue + " ";
        sqlstr += txtReceiver.Text.Trim() == "" ? "" : " and ORDER_GETER like '%" + txtReceiver.Text.Trim() + "%' ";
        sqlstr += dropOrderSuggestion.SelectedValue == "-1" ? "" : " and ORDER_STATETYPECODE='" + dropOrderSuggestion.SelectedValue + "' ";
        sqlstr += txtDeliverStartDate.Text.Trim() == "" ? "" : " and ORDER_SENDDATE>='" + txtDeliverStartDate.Text.Trim() + "' ";
        sqlstr += txtDeliverEndDate.Text.Trim() == "" ? "" : " and ORDER_SENDDATE<='" + DateTime.Parse(txtDeliverEndDate.Text.Trim()).AddDays(1).ToString() + "' ";
        sqlstr += txtDeliverBillId.Text.Trim() == "" ? "" : " and ORDER_TRANBILLCODE LIKE '%" + txtDeliverBillId.Text.Trim() + "%' ";

        if (this.Panel1.Visible == true)
        {
            sqlstr += txtgddh.Text.Trim() == "" ? "" : " and ORDER_GETERPHONE1 LIKE '%" + txtgddh.Text.Trim() + "%' ";
            sqlstr += txtsj.Text.Trim() == "" ? "" : " and ORDER_GETERPHONE2 LIKE '%" + txtsj.Text.Trim() + "%' ";
            sqlstr += txtaddress.Text.Trim() == "" ? "" : " and ORDER_GETADDRESS LIKE '%" + txtaddress.Text.Trim() + "%' ";
            sqlstr += txtspdm.Text.Trim() == "" ? "" : " and OD_CMDCODE LIKE '%" + txtspdm.Text.Trim() + "%' ";
            sqlstr += drpColor.SelectedValue == "-1" ? "" : " and OD_COLORCODE = '" + drpColor.SelectedValue + "' ";
            sqlstr += drpSize.SelectedValue == "-1" ? "" : " and OD_SIZECODE= '" + drpSize.SelectedValue + "' ";
        }

        sqlstr += ddlinvoice.SelectedIndex < 1 ? "" : " and OrderDoc.ORDER_NINV=" + ddlinvoice.SelectedValue;  //发票

        if (ddl_lockmanager.Visible == true)
        {
            sqlstr += ddl_lockmanager.SelectedIndex < 1 ? "" : " and OrderDoc.BYZD20='" + ddl_lockmanager.SelectedValue + "'";//发货锁人
        }


        //string sort = ddlSort.SelectedValue;
        //bool AscDesc = ddlSortDrect.SelectedValue=="asc"?false:true;
        sqlstr += " order by " + ddlSort.SelectedValue + " " + ddlSortDrect.SelectedValue;

        int recordCount;
        this.DstOrders = new BLL.ORDERDOC().GetToShipperOrder(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, sqlstr, out recordCount);
        //this.DstOrders = new BLL.ORDERDOC().GetList2(TableName.ToString(), FieldName.ToString(), false, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, sort, AscDesc, sqlstr, out pagecount, out recordCount);

        rptOrderList.DataSource = this.DstOrders;
        rptOrderList.DataBind();
        AspNetPager1.RecordCount = recordCount;
        init_PCH();
    }

    void BindSerach()
    {
        string sqlstr = " select DISTINCT ORDER_ID,ORDER_SEND,ORDER_DELETE,ORDER_CLEAR,ORDER_QTY,ORDER_AAMT,ORDER_CREATEDATE,ORDER_SENDDATE, ORDER_CHECKDATE," +
            "ORDER_CUSTOMERCODE,V_Customer.GKMC,ORDERFROM.OF_NAME,DEALTYPE.DT_NAME,TRANER.TRANER_NAME,ORDER_PRINT,ORDER_TPRINT,ORDER_ACHECKDATE ," +
            "ORDER_SECDEAL,ORDER_TRANBILLCODE,ORDER_GETER ,V_Customer.BYZD5 as NIKE from OrderDoc left join V_Customer " +
            "on OrderDoc.ORDER_CUSTOMERCODE = V_Customer.DM left join ORDERFROM on OrderDoc.ORDER_OFCODE = ORDERFROM.OF_CODE" +
            " left join DEALTYPE on OrderDoc.ORDER_DTCODE = DEALTYPE.DT_CODE left join TRANER on OrderDoc.ORDER_TRANERCODE =  TRANER.TRANER_CODE" +
            " left join ORDERDETAIL  on OrderDoc.ORDER_ID = ORDERDETAIL.OD_ID where ORDER_CHECK=1 and ORDER_ACHECK=1 and ORDER_DELETE=0 ";
        //string sqlstr="";
        sqlstr += txtOrderId.Text.Trim() == "" ? "" : " and order_id LIKE '%" + txtOrderId.Text.Trim() + "%' ";
        sqlstr += txtCustomerId.Text.Trim() == "" ? "" : " and order_customercode like '%" + txtCustomerId.Text.Trim() + "%' ";
        sqlstr += txtNickName.Text.Trim() == "" ? "" : " and V_Customer.byzd5 like '%" + txtNickName.Text.Trim() + "%' ";
        sqlstr += txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ";
        sqlstr += txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + DateTime.Parse(txtOrderEndDate.Text.Trim()).AddDays(1).ToString() + "' ";
        sqlstr += dropOrderSource.SelectedValue.Trim() == "-1" ? "" : " and ORDER_OFCODE='" + dropOrderSource.SelectedValue + "' ";
        sqlstr += dropDealType.SelectedValue.Trim() == "-1" ? "" : " and ORDER_APAY='" + dropDealType.SelectedValue + "' ";
        sqlstr += dropDelete.SelectedValue == "-1" ? "" : " and ORDER_DELETE=" + Int32.Parse(dropDelete.SelectedValue) + " ";
        sqlstr += dropDeliver.SelectedValue == "-1" ? "" : " and ORDER_SEND=" + Int32.Parse(dropDeliver.SelectedValue) + " ";
        sqlstr += dropClear.SelectedValue == "-1" ? "" : " and ORDER_Clear=" + Int32.Parse(dropClear.SelectedValue) + " ";
        sqlstr += dropTraner.SelectedValue == "-1" ? "" : " and ORDER_TRANERCODE='" + dropTraner.SelectedValue + "' ";
        sqlstr += dropExpressPrint.SelectedValue == "-1" ? "" : "and ORDER_TPRINT='" + dropExpressPrint.SelectedValue + "' ";
        sqlstr += dropDeliverPrint.SelectedValue == "-1" ? "" : "and ORDER_PRINT='" + dropDeliverPrint.SelectedValue + "' ";
        sqlstr += dropAssureDeal.SelectedValue == "-1" ? "" : " and ORDER_SECDEAL=" + dropAssureDeal.SelectedValue + " ";
        sqlstr += txtReceiver.Text.Trim() == "" ? "" : " and ORDER_GETER like '%" + txtReceiver.Text.Trim() + "%' ";
        sqlstr += dropOrderSuggestion.SelectedValue == "-1" ? "" : " and ORDER_STATETYPECODE='" + dropOrderSuggestion.SelectedValue + "' ";
        sqlstr += txtDeliverStartDate.Text.Trim() == "" ? "" : " and ORDER_SENDDATE>='" + txtDeliverStartDate.Text.Trim() + "' ";
        sqlstr += txtDeliverEndDate.Text.Trim() == "" ? "" : " and ORDER_SENDDATE<='" + DateTime.Parse(txtDeliverEndDate.Text.Trim()).AddDays(1).ToString() + "' ";
        sqlstr += txtDeliverBillId.Text.Trim() == "" ? "" : " and ORDER_TRANBILLCODE LIKE '%" + txtDeliverBillId.Text.Trim() + "%' ";

        if (this.Panel1.Visible == true)
        {
            sqlstr += txtgddh.Text.Trim() == "" ? "" : " and ORDER_GETERPHONE1 LIKE '%" + txtgddh.Text.Trim() + "%' ";
            sqlstr += txtsj.Text.Trim() == "" ? "" : " and ORDER_GETERPHONE2 LIKE '%" + txtsj.Text.Trim() + "%' ";
            sqlstr += txtaddress.Text.Trim() == "" ? "" : " and ORDER_GETADDRESS LIKE '%" + txtaddress.Text.Trim() + "%' ";
            sqlstr += txtspdm.Text.Trim() == "" ? "" : " and OD_CMDCODE LIKE '%" + txtspdm.Text.Trim() + "%' ";
        }
        string orderby = " order by " + ddlSort.SelectedValue + " " + ddlSortDrect.SelectedValue;

        DstOrders = DBUtility.SqlHelper.Query(DBUtility.SqlHelper.LocalSqlServer, sqlstr + orderby);
        //DstOrders = new BLL.ORDERDOC().P_GetOrderList_OrderBy(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize),AspNetPager1.PageSize,sqlstr,orderby);        
        rptOrderList.DataSource = this.DstOrders;
        rptOrderList.DataBind();
        AspNetPager1.RecordCount = DstOrders.Tables[0].Rows.Count;
    }
    #endregion

    #region 分页
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    #endregion

    protected void rptOrderList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (ItemCommand != null)
            ItemCommand(source, e);
    }

    private int GetStartIndex(int pageIndex, int pageSize)
    {
        return 1 + (pageIndex - 1) * pageSize;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
        //BindSerach();
        Bind();
        WriteCookie();

    }

    #region 发货
    /// <summary>
    /// 批量发货
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDeliver_Click(object sender, EventArgs e)
    {
        try
        {
            if (!Check.CheckPermission("500100", "00014"))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('无权操作');document.getElementById('btnSearch').click()", true);
                return;
            }

            Model.PICI pc = new BLL.PICI().GetModel(Share.UserValue(0), "PCH_ID");
            if (pc == null)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请先开始一个批次！');document.getElementById('btnSearch').click()", true);
                return;
            }
            if (this.Selected.Count == 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择要发货的订单！');document.getElementById('btnSearch').click()", true);
                return;
            }
            CheckBox chkSend;
            foreach (RepeaterItem temp in rptOrderList.Items)
            {
                chkSend = (CheckBox)temp.FindControl("CheckBox4");
                if (chkSend.Checked == true)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('您选择发货的订单中存在已发货订单，请重新选择！');document.getElementById('btnSearch').click()", true);
                    return;
                }
            }

            bool checkFlag = true;
            foreach (string tmp in this.Selected)
            {

                Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(tmp);

                if (order.ORDER_TRANBILLCODE.Length <= 4)
                {
                    checkFlag = false;
                }
            }
            if (!checkFlag)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('订单的物流单号不允许少于4个字符长度，请修改保存后再发货');document.getElementById('btnSearch').click()", true);
                return;
            }

            int countSuccess = 0; int countSend = 0;
            foreach (string temp in this.Selected)
            {
                Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(temp);
                if (order != null)
                {
                    if (order.ORDER_SEND == 0)
                    {
                        countSend++;
                        bool result = Deliver(temp, Share.UserValue(0), pc.PCH_ID);
                        if (result)
                        {
                            countSuccess++;
                            Share.InsertLog("500100", "00014");

                            //发货成功后给客户发送通知邮件
                            List<Model.EMAILBODY> bodylist = new BLL.EMAILBODY().GetAllList();
                            if (bodylist != null)
                            {
                                if (bodylist.Count > 0)
                                {
                                    Model.EMAILBODY body = bodylist[0];
                                    if (body.DeliverySwitch == 1)
                                    {
                                        Model.V_CUSTOMER customer = new BLL.V_CUSTOMER().GetModel(order.ORDER_CUSTOMERCODE);
                                        if (customer != null)
                                        {
                                            BLL.EmailSendBL bl = new BLL.EmailSendBL(customer.EMAIL, "DeliverySubject", "");
                                            bl.SendDeliveryEmail(temp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (countSend != this.Selected.Count)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('部分订单已经发过货，请核对后重新发货！');document.getElementById('btnSearch').click()", true);
            }
            if (countSuccess != this.Selected.Count)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('部分订单未发货成功，请核对后重新发货！');document.getElementById('btnSearch').click()", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('发货成功！');document.getElementById('btnSearch').click()", true);

            }
            Bind();
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert(" + ex.Message + ");document.getElementById('btnSearch').click()", true);
            return;
        }
    }
    #region
    //public bool Deliver(string orderId, string operatorId)
    //{
    //    int pageCount, recordCount;
    //    Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(orderId);
    //    List<Model.ORDERDETAIL> orderDetails = new BLL.ORDERDETAIL().GetList(100, 1, " OD_DETAILID ", false, " and OD_ID='" + orderId + "' ", out pageCount, out recordCount);
    //    IList<Model.PAYDETAIL> payDetails = new SQLServerDAL.PAYDETAIL().GetPayDetailById(orderId);

    //    if (order != null && orderDetails != null && payDetails != null)
    //    {
    //        if (orderDetails.Count == 0)
    //        {
    //            throw new Exception("系统无法查询到该订单的明细，不能执行发货操作！");
    //        }
    //        if (order.ORDER_DTCODE != "003")
    //        {
    //            if (payDetails.Count == 0)
    //            {
    //                throw new Exception("系统无法查询到该订单的支付明细，不能执行发货操作！");
    //            }
    //        }

    //        #region 非货到付款流程


    //        if (order.ORDER_APAY == 0)
    //        {
    //            #region 含担保交易


    //            if (order.ORDER_SECDEAL == 1)
    //            {
    //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
    //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

    //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
    //                if (userInfo == null)
    //                {
    //                    throw new Exception("系统内无此会员信息！");
    //                }
    //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

    //                if (userAccount == null)
    //                {
    //                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
    //                    strSqlToUpdateBStyleDB.Append("',0)|");

    //                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateErpDB.Append(userInfo.DM);
    //                    strSqlToUpdateErpDB.Append("',0)|");

    //                }

    //                strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
    //                strSqlToUpdateBStyleDB.Append(operatorId);
    //                strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
    //                strSqlToUpdateBStyleDB.Append(DateTime.Now);
    //                strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
    //                strSqlToUpdateBStyleDB.Append(orderId);
    //                strSqlToUpdateBStyleDB.Append("'|");


    //                for (int i = 0; i < orderDetails.Count; i++)
    //                {
    //                    strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
    //                    strSqlToUpdateBStyleDB.Append(" where SPDM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
    //                    strSqlToUpdateBStyleDB.Append("' and GG1DM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
    //                    strSqlToUpdateBStyleDB.Append("' and GG2DM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
    //                    strSqlToUpdateBStyleDB.Append("'|");
    //                }



    //                if (strSqlToUpdateErpDB.ToString() == "")
    //                {
    //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
    //                    char[] charToTrim = new char[] { '|' };
    //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
    //                    return new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
    //                }
    //                else
    //                {
    //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
    //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

    //                    char[] charToTrim = new char[] { '|' };
    //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
    //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

    //                    ERP.Service webService = new ERP.Service();
    //                    return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
    //                }

    //            }
    //            #endregion
    //            #region 不含担保交易
    //            else if (order.ORDER_SECDEAL == 0)
    //            {
    //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
    //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

    //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
    //                if (userInfo == null)
    //                {
    //                    throw new Exception("系统内无此会员信息！");
    //                }
    //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

    //                if (userAccount == null)
    //                {
    //                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
    //                    strSqlToUpdateBStyleDB.Append("',0)|");

    //                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateErpDB.Append(userInfo.DM);
    //                    strSqlToUpdateErpDB.Append("',0)|");
    //                }

    //                if (order.ORDER_CLEAR == 1)
    //                {

    //                    strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
    //                    strSqlToUpdateBStyleDB.Append(operatorId);
    //                    strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
    //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
    //                    strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
    //                    strSqlToUpdateBStyleDB.Append(orderId);
    //                    strSqlToUpdateBStyleDB.Append("'|");

    //                    for (int i = 0; i < orderDetails.Count; i++)
    //                    {
    //                        strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
    //                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
    //                        strSqlToUpdateBStyleDB.Append(" where SPDM='");
    //                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
    //                        strSqlToUpdateBStyleDB.Append("' and GG1DM='");
    //                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
    //                        strSqlToUpdateBStyleDB.Append("' and GG2DM='");
    //                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
    //                        strSqlToUpdateBStyleDB.Append("'|");
    //                    }

    //                    decimal points = Convert.ToDecimal(0.00);
    //                    foreach (Model.ORDERDETAIL temp in orderDetails)
    //                    {
    //                        points += temp.OD_ADDITG;
    //                    }

    //                    string strUpdateVipSetSqlString = new BLL.V_VIPSET().BuildUpdateVipSetSqlString(0, 0, points, order.ORDER_CUSTOMERCODE);
    //                    strSqlToUpdateBStyleDB.Append(strUpdateVipSetSqlString);
    //                    strSqlToUpdateErpDB.Append(strUpdateVipSetSqlString);

    //                    string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(order.ORDER_PAYAMT - order.ORDER_AAMT, userInfo.DM);
    //                    strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
    //                    strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);


    //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
    //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

    //                    char[] charToTrim = new char[] { '|' };
    //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
    //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

    //                    ERP.Service webService = new ERP.Service();
    //                    return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);

    //                }
    //            #endregion
    //            }
    //        #endregion
    //            #region 货到付款流程
    //            else if (order.ORDER_APAY == 1)
    //            {
    //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
    //                if (userInfo == null)
    //                {
    //                    throw new Exception("系统内无此会员信息！");
    //                }
    //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

    //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
    //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

    //                if (userAccount == null)
    //                {
    //                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
    //                    strSqlToUpdateBStyleDB.Append("',0)|");

    //                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
    //                    strSqlToUpdateErpDB.Append(userInfo.DM);
    //                    strSqlToUpdateErpDB.Append("',0)|");
    //                }



    //                strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
    //                strSqlToUpdateBStyleDB.Append(operatorId);
    //                strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
    //                strSqlToUpdateBStyleDB.Append(DateTime.Now);
    //                strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
    //                strSqlToUpdateBStyleDB.Append(orderId);
    //                strSqlToUpdateBStyleDB.Append("'|");


    //                for (int i = 0; i < orderDetails.Count; i++)
    //                {
    //                    strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
    //                    strSqlToUpdateBStyleDB.Append(" where SPDM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
    //                    strSqlToUpdateBStyleDB.Append("' and GG1DM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
    //                    strSqlToUpdateBStyleDB.Append("' and GG2DM='");
    //                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
    //                    strSqlToUpdateBStyleDB.Append("'|");
    //                }

    //                if (strSqlToUpdateErpDB.ToString() == "")
    //                {
    //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
    //                    char[] charToTrim = new char[] { '|' };
    //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
    //                    return new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
    //                }
    //                else
    //                {
    //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
    //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

    //                    char[] charToTrim = new char[] { '|' };
    //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
    //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

    //                    ERP.Service webService = new ERP.Service();
    //                    return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
    //                }
    //            }
    //            #endregion

    //            else
    //            {
    //                return false;
    //            }
    //        }
    //        else
    //        {
    //            throw new Exception("查询数据时出现错误，请重新执行发货操作！");
    //        }



    //    }
    //    return false;
    //}
    #endregion
    public bool Deliver(string orderId, string operatorId, string pch)
    {

        int pageCount, recordCount;
        Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(orderId);
        List<Model.ORDERDETAIL> orderDetails = new BLL.ORDERDETAIL().GetList(100, 1, " OD_DETAILID ", false, " and OD_ID='" + orderId + "' ", out pageCount, out recordCount);
        IList<Model.PAYDETAIL> payDetails = new SQLServerDAL.PAYDETAIL().GetPayDetailById(orderId);
        if (order != null && orderDetails != null && payDetails != null)
        {
            if (order.ORDER_SEND == 1)
            {
                Share.Alert(this, "该订单已发货");
                return false;
            }
            if (orderDetails.Count == 0)
            {
                Share.Alert(this, "系统无法查询到该订单的明细，不能执行发货操作");
                return false;
            }
            if (order.ORDER_APAY != 1)
            {
                if (payDetails.Count == 0)
                {
                    Share.Alert(this, "系统无法查询到该订单的支付明细，不能执行发货操作！");
                    return false;
                }
            }
            if (order.ORDER_CHECK != 1 || order.ORDER_ACHECK != 1 || order.ORDER_DELETE != 0)
            {
                Share.Alert(this, "订单不符合发货条件,未能发货！");
                return false;
            }
            #region 非货到付款流程



            if (order.ORDER_APAY == 0)
            {
                #region 含担保交易



                if (order.ORDER_SECDEAL == 1)
                {
                    StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
                    StringBuilder strSqlToUpdateErpDB = new StringBuilder();

                    Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
                    if (userInfo == null)
                    {
                        Share.Alert(this, "系统内无此会员信息！");
                        return false;
                    }
                    Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

                    if (userAccount == null)
                    {
                        strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                        strSqlToUpdateBStyleDB.Append(userInfo.DM);
                        strSqlToUpdateBStyleDB.Append("',0)|");

                        strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                        strSqlToUpdateErpDB.Append(userInfo.DM);
                        strSqlToUpdateErpDB.Append("',0)|");

                    }

                    strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
                    strSqlToUpdateBStyleDB.Append(operatorId);
                    strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
                    strSqlToUpdateBStyleDB.Append("',BYZD21='");
                    strSqlToUpdateBStyleDB.Append(pch);
                    strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
                    strSqlToUpdateBStyleDB.Append(orderId);
                    strSqlToUpdateBStyleDB.Append("'|");


                    for (int i = 0; i < orderDetails.Count; i++)
                    {
                        strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
                        strSqlToUpdateBStyleDB.Append(" where CKDM='");
                        strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["ckdm"].ToString());
                        strSqlToUpdateBStyleDB.Append("' and KWDM='");
                        strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["kwdm"].ToString());
                        strSqlToUpdateBStyleDB.Append("' and SPDM='");
                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
                        strSqlToUpdateBStyleDB.Append("' and GG1DM='");
                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
                        strSqlToUpdateBStyleDB.Append("' and GG2DM='");
                        strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
                        strSqlToUpdateBStyleDB.Append("'|");
                    }



                    if (strSqlToUpdateErpDB.ToString() == "")
                    {
                        string stringSql = strSqlToUpdateBStyleDB.ToString();
                        char[] charToTrim = new char[] { '|' };
                        string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
                        return new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
                    }
                    else
                    {
                        string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
                        string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

                        char[] charToTrim = new char[] { '|' };
                        string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
                        string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

                        LX_Manage.ERP.Service webService = new LX_Manage.ERP.Service();
                        return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
                    }



                }
                #endregion
                #region 不含担保交易
                else if (order.ORDER_SECDEAL == 0)
                {
                    StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
                    StringBuilder strSqlToUpdateErpDB = new StringBuilder();

                    Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
                    if (userInfo == null)
                    {
                        Share.Alert(this, "系统内无此会员信息！");
                        return false;
                    }
                    Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

                    if (userAccount == null)
                    {
                        strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                        strSqlToUpdateBStyleDB.Append(userInfo.DM);
                        strSqlToUpdateBStyleDB.Append("',0)|");

                        strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                        strSqlToUpdateErpDB.Append(userInfo.DM);
                        strSqlToUpdateErpDB.Append("',0)|");
                    }

                    if (order.ORDER_CLEAR == 1)
                    {

                        strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
                        strSqlToUpdateBStyleDB.Append(operatorId);
                        strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
                        strSqlToUpdateBStyleDB.Append(DateTime.Now);
                        strSqlToUpdateBStyleDB.Append("',BYZD21='");
                        strSqlToUpdateBStyleDB.Append(pch);
                        strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
                        strSqlToUpdateBStyleDB.Append(orderId);
                        strSqlToUpdateBStyleDB.Append("'|");

                        for (int i = 0; i < orderDetails.Count; i++)
                        {
                            strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
                            strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
                            strSqlToUpdateBStyleDB.Append(" where CKDM='");
                            strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["ckdm"].ToString());
                            strSqlToUpdateBStyleDB.Append("' and KWDM='");
                            strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["kwdm"].ToString());
                            strSqlToUpdateBStyleDB.Append("' and SPDM='");
                            strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
                            strSqlToUpdateBStyleDB.Append("' and GG1DM='");
                            strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
                            strSqlToUpdateBStyleDB.Append("' and GG2DM='");
                            strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
                            strSqlToUpdateBStyleDB.Append("'|");
                        }

                        decimal points = Convert.ToDecimal(0.00);
                        foreach (Model.ORDERDETAIL temp in orderDetails)
                        {
                            points += temp.OD_ADDITG;
                        }

                        string strUpdateVipSetSqlString = new BLL.V_VIPSET().BuildUpdateVipSetSqlString(0, 0, 0, order.ORDER_CUSTOMERCODE);
                        strSqlToUpdateBStyleDB.Append(strUpdateVipSetSqlString);
                        strSqlToUpdateErpDB.Append(strUpdateVipSetSqlString);

                        if (order.ORDER_PAYAMT - order.ORDER_AAMT > 0)
                        {
                            string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(order.ORDER_PAYAMT - order.ORDER_AAMT, userInfo.DM);
                            strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
                            strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

                            string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("005", order.ORDER_ID, operatorId, operatorId, order.ORDER_CUSTOMERCODE, order.ORDER_PAYAMT - order.ORDER_AAMT);
                            strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);

                        }

                        string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
                        string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

                        char[] charToTrim = new char[] { '|' };
                        string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
                        string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

                        LX_Manage.ERP.Service webService = new LX_Manage.ERP.Service();
                        return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);

                    }
                    else
                    {
                        Share.Alert(this, "该订单未结算，因此不能发货！");
                        return false;
                    }
                }
                #endregion
            }
            #endregion
            #region 货到付款流程
            else if (order.ORDER_APAY == 1)
            {
                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
                if (userInfo == null)
                {
                    Share.Alert(this, "系统内无此会员信息！");
                    return false;
                }
                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

                if (userAccount == null)
                {
                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
                    strSqlToUpdateBStyleDB.Append("',0)|");

                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                    strSqlToUpdateErpDB.Append(userInfo.DM);
                    strSqlToUpdateErpDB.Append("',0)|");
                }


                strSqlToUpdateBStyleDB.Append("update ORDERDOC set ORDER_SEND=1,ORDER_SENDER='");
                strSqlToUpdateBStyleDB.Append(operatorId);
                strSqlToUpdateBStyleDB.Append("',ORDER_SENDDATE='");
                strSqlToUpdateBStyleDB.Append(DateTime.Now);
                strSqlToUpdateBStyleDB.Append("',BYZD21='");
                strSqlToUpdateBStyleDB.Append(pch);
                strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
                strSqlToUpdateBStyleDB.Append(orderId);
                strSqlToUpdateBStyleDB.Append("'|");


                for (int i = 0; i < orderDetails.Count; i++)
                {
                    strSqlToUpdateBStyleDB.Append("update SPKCB set SL=SL-");
                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_QTY);
                    strSqlToUpdateBStyleDB.Append(" where CKDM='");
                    strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["ckdm"].ToString());
                    strSqlToUpdateBStyleDB.Append("' and KWDM='");
                    strSqlToUpdateBStyleDB.Append(ConfigurationManager.AppSettings["kwdm"].ToString());
                    strSqlToUpdateBStyleDB.Append("' and SPDM='");
                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_CMDCODE);
                    strSqlToUpdateBStyleDB.Append("' and GG1DM='");
                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_COLORCODE);
                    strSqlToUpdateBStyleDB.Append("' and GG2DM='");
                    strSqlToUpdateBStyleDB.Append(orderDetails[i].OD_SIZECODE);
                    strSqlToUpdateBStyleDB.Append("'|");
                }

                if (strSqlToUpdateErpDB.ToString() == "")
                {
                    string stringSql = strSqlToUpdateBStyleDB.ToString();
                    char[] charToTrim = new char[] { '|' };
                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
                    return new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
                }
                else
                {
                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

                    char[] charToTrim = new char[] { '|' };
                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

                    LX_Manage.ERP.Service webService = new LX_Manage.ERP.Service();
                    return webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
                }
            }
            #endregion

            else
            {
                return false;
            }
        }
        else
        {
            Share.Alert(this, "查询数据时出现错误，请重新执行发货操作！");
            return false;
        }
        return false;

    }
    #endregion

    #region 打印
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("500100", "00020"))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('无权操作');document.getElementById('btnSearch').click()", true);
            return;
        }
        StringBuilder sbSql = new StringBuilder();
        string strOrderId = "";
        for (int i = 0; i < this.Selected.Count; i++)
        {           
            if (i + 1 == this.Selected.Count)
            {
                strOrderId += this.Selected[i];
            }
            else
            {
                strOrderId += this.Selected[i] + "|";
            }
            sbSql.Append("update orderdoc set ORDER_TPRINT=1,ORDER_TPRINTER='");
            sbSql.Append(Share.UserValue(0));
            sbSql.Append("',ORDER_TPRINTDATE='");
            sbSql.Append(DateTime.Now);
            sbSql.Append("',ORDER_TPRINTCOUNT=ORDER_TPRINTCOUNT+1 where order_id='");
            sbSql.Append(this.Selected[i]);
            sbSql.Append("'|");

        }
        if (strOrderId == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择需要打印的发货单！');document.getElementById('btnSearch').click()", true);
            return;
        }
        else
        {
            if (LockFlag == "1")
            {
                string ret = "";
                new BLL.ORDERDOC().checklock(strOrderId, Share.UserValue(0), out ret);
                if (ret.Length > 0)
                {
                    Share.Alert(this, ret);
                    return;
                }
            }
        }
        if (dropExpressBill.SelectedIndex == 0)
        {
            //CheckBox chk1;
            //CheckBox chk2;
            //Label lblTranerName1;
            //Label lblTranerName2;
            //for (int i = 0; i < rptOrderList.Items.Count; i++)
            //{
            //    chk1 = (CheckBox)rptOrderList.Items[i].FindControl("chkChoose");
            //    if (chk1.Checked)
            //    {
            //        for (int j = 0; j < rptOrderList.Items.Count; j++)
            //        {
            //            chk2 = (CheckBox)rptOrderList.Items[j].FindControl("chkChoose");
            //            if (chk2.Checked)
            //            {
            //                lblTranerName1 = (Label)rptOrderList.Items[i].FindControl("lblTranerName");
            //                lblTranerName2 = (Label)rptOrderList.Items[j].FindControl("lblTranerName");
            //                if (lblTranerName1.Text != lblTranerName2.Text)
            //                {
            //                    Response.Write("<script>alert('一次只能打印一家物流公司的物流单！')");
            //                    return;
            //                }
            //            }
            //        }
            //    }
            //}

            //for (int i = 0; i < rptOrderList.Items.Count; i++)
            //{
            //    chk1 = (CheckBox)rptOrderList.Items[i].FindControl("chkChoose");
            //    if (chk1.Checked)
            //    {
            //        lblTranerName1 = (Label)rptOrderList.Items[i].FindControl("lblTranerName");
            //        foreach (ListItem temp in dropTraner.Items)
            //        {
            //            if (temp.Text == lblTranerName1.Text)
            //            {
            //                this.DealType = temp.Value;
            //                break;
            //            }
            //        }
            //    }
            //}

            //Page.RegisterStartupScript("StartUp", "window.open('printwindow.aspx?tranerId=" + this.DealType + "&orderId=" + strOrderId + "')");

            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择物流单打印模板');document.getElementById('btnSearch').click()", true);
            return;

        }
        else
        {
            string stringSql = sbSql.ToString();
            char[] charArray = new char[] { '|' };
            string[] sqlCommandArray = stringSql.TrimEnd(charArray).Split(charArray);
            if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
            {
                string isRPT = ConfigurationManager.AppSettings["PrintMethod"];
                if (isRPT == "1")
                {//active report 方法打印物流单


                    string sprinttype = "0";//默认打印时不显示界面
                    if (ConfigurationManager.AppSettings["PrintType"] != null && ConfigurationManager.AppSettings["PrintType"] != "") sprinttype = ConfigurationManager.AppSettings["PrintType"];
                    //By ltl add 打印
                    string openurlstr = "";
                    for (int i = 0; i < strOrderId.Split('|').Length; i++)
                    {
                        openurlstr += "window.open('../BillReport.aspx?DJBH=" + strOrderId.Split('|')[i] + "&ReportModule=FHGL/WLD&ReportName=WLD&PrintType=" + sprinttype + "');";
                    }
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "" + openurlstr + ";document.getElementById('btnSearch').click()", true);
                }
                else
                {//原始方法打印物流单


                    ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "window.open('printwindow.aspx?tranerId=" + dropExpressBill.SelectedValue + "&orderId=" + strOrderId + "');document.getElementById('btnSearch').click()", true);
                }
            }
        }
    }

    protected void btnPrintDeliver_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("500100", "00020"))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('无权操作');document.getElementById('btnSearch').click()", true);
            return;
        }

        StringBuilder sbSql = new StringBuilder();
        string strOrderId = "";
        for (int i = 0; i < this.Selected.Count; i++)
        {            

            if (i + 1 == this.Selected.Count)
            {
                strOrderId += this.Selected[i];
            }
            else
            {
                strOrderId += this.Selected[i] + "|";
            }            
            sbSql.Append("update orderdoc set ORDER_PRINT=1,ORDER_PRINTER='");
            sbSql.Append(Share.UserValue(0));
            sbSql.Append("',ORDER_PRINTDATE='");
            sbSql.Append(DateTime.Now);
            sbSql.Append("',ORDER_PRINTCOUNT=ORDER_PRINTCOUNT+1 where order_id='");
            sbSql.Append(this.Selected[i]);
            sbSql.Append("'|");

        }
        if (strOrderId == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择需要打印的发货单！');document.getElementById('btnSearch').click()", true);
            return;
        }
        else
        {
            if (LockFlag == "1")
            {
                string ret = "";
                new BLL.ORDERDOC().checklock(strOrderId, Share.UserValue(0), out ret);
                if (ret.Length > 0)
                {
                    Share.Alert(this, ret);
                    return;
                }
            }
        }
        string stringSql = sbSql.ToString();
        char[] charArray = new char[] { '|' };
        string[] sqlCommandArray = stringSql.TrimEnd(charArray).Split(charArray);
        string openurlstr = "";
        if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
        {
            if (ConfigurationManager.AppSettings["IsXtlProject"].ToString() == "1")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "window.open('PrintDeliverBill.aspx?orderId=" + strOrderId + "');document.getElementById('btnSearch').click()", true);
            }
            else if (ConfigurationManager.AppSettings["IsXtlProject"].ToString() == "0")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "window.open('PrintDeliverBillWindow.aspx?orderId=" + strOrderId + "');document.getElementById('btnSearch').click()", true);

                //Page.RegisterStartupScript("StartUp", "window.open('PrintDeliverBillWindow.aspx?orderId=" + strOrderId + "')");

            }
            //中国资本的配货单打印格式
            else if (ConfigurationManager.AppSettings["IsXtlProject"].ToString() == "2")
            {
                string sprinttype = "0";//默认打印时不显示界面
                if (ConfigurationManager.AppSettings["PrintType"] != null && ConfigurationManager.AppSettings["PrintType"] != "") sprinttype = ConfigurationManager.AppSettings["PrintType"];
                //By winner add打印
                for (int i = 0; i < strOrderId.Split('|').Length; i++)
                {
                    openurlstr += "window.open('../BillReport.aspx?DJBH=" + strOrderId.Split('|')[i] + "&ReportModule=FHGL/SDFHD&ReportName=SDFHD&PrintType=" + sprinttype + "');";
                }
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "" + openurlstr + ";document.getElementById('btnSearch').click()", true);
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('更新配货单打印次数时出现错误，请重试！');document.getElementById('btnSearch').click()", true);
            return;
        }
    }
    #endregion

    #region rptOrderList_ItemDataBound
    protected void rptOrderList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            HiddenField hf = (HiddenField)e.Item.FindControl("hfOrderId");
            DataSet ds = new BLL.ORDERNOTE().GetOrderNoteById(hf.Value);
            if (ds.Tables[0].Rows.Count > 0)
            {
                HyperLink hl = (HyperLink)e.Item.FindControl("sdss");
                System.Drawing.Color a = System.Drawing.Color.FromName(ds.Tables[0].Rows[0]["ST_COLOR"].ToString().Trim());
                hl.BackColor = a;
                hl.ToolTip = ds.Tables[0].Rows[0]["ON_NOTE"].ToString();
            }
            //重新设置选定项


            CheckBox cb = e.Item.FindControl("chkChoose") as CheckBox;

            if (hdOrders.Value.IndexOf(hf.Value) != -1)
            {
                cb.Checked = true;
            }
        }
        if (e.Item.ItemType == ListItemType.Footer)
        {
            Repeater rp = (Repeater)sender;
            DataSet ds = (DataSet)rp.DataSource;

            string num_sum = ds.Tables[1].Rows[0][0].ToString();

            Label lbl_SL_SUM = (Label)e.Item.FindControl("lbl_SL_SUM");

            lbl_SL_SUM.Text = "总共有" + num_sum + "张订单";
        }
    }
    #endregion

    #region 打开/隐藏高级条件
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (this.Panel1.Visible == false)
        {
            this.Panel1.Visible = true;
            Button3.Text = "<<";

        }
        else
        {
            this.Panel1.Visible = false;
            Button3.Text = ">>";

        }


    }
    #endregion

    #region 修改物流公司
    protected void btnUpdateTraner_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("500100", "00002"))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('无权操作！');document.getElementById('btnSearch').click()", true);
            return;
        }
        if (dropTraner.SelectedIndex == 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择配送方式！');document.getElementById('btnSearch').click()", true);
            return;
        }
        if (this.Selected.Count == 0)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择需要修改的发货单！');document.getElementById('btnSearch').click()", true);
            return;
        }
        List<Model.TRANER> traners = new BLL.TRANER().GetAllList();
        if (traners != null && traners.Count > 0)
        {
            for (int i = 0; i < traners.Count; i++)
            {
                if (traners[i].TRANER_CODE == dropTraner.SelectedValue)
                {
                    if (traners[i].TRANER_STOP == 1)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('要修改的物流公司已经被停用，因此不可以修改！');document.getElementById('btnSearch').click()", true);
                        return;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('');document.getElementById('btnSearch').click()", true);
            return;
        }

        StringBuilder sbSql = new StringBuilder();

        for (int i = 0; i < this.Selected.Count; i++)
        {
            sbSql.Append("update orderdoc set ORDER_TRANERCODE='");
            sbSql.Append(dropTraner.SelectedValue);
            sbSql.Append("' where order_id='");
            sbSql.Append(this.Selected[i]);
            sbSql.Append("'|");

        }

        string stringSql = sbSql.ToString();
        char[] charArray = new char[] { '|' };
        string[] sqlCommandArray = stringSql.TrimEnd(charArray).Split(charArray);
        if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('修改成功');window.location.href='invoices.aspx'", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('修改失败');window.location.href='invoices.aspx'", true);
        }

    }
    #endregion

    #region 保存查询条件
    private void WriteCookie()
    {
        if (chkCondition.Checked)
        {
            HttpCookie existCookie = Request.Cookies["Condition"];
            if (existCookie == null)
            {
                HttpCookie cookie = new HttpCookie("Condition");
                cookie.Expires = DateTime.Now.AddHours(1);

                //cookie.Path = Request.ApplicationPath + "DeliverGoodsManagement/Invoices.aspx";

                cookie.Values.Add("chkCondition", chkCondition.Checked.ToString());
                cookie.Values.Add("orderId", txtOrderId.Text.Trim());
                cookie.Values.Add("deliverId", txtDeliverBillId.Text.Trim());
                cookie.Values.Add("customerId", txtCustomerId.Text.Trim());
                cookie.Values.Add("nickName", txtNickName.Text.Trim());
                cookie.Values.Add("receiver", txtReceiver.Text.Trim());
                cookie.Values.Add("orderStart", txtOrderStartDate.Text.Trim());
                cookie.Values.Add("orderEnd", txtOrderEndDate.Text.Trim());
                cookie.Values.Add("deliverStart", txtDeliverStartDate.Text.Trim());
                cookie.Values.Add("deliverEnd", txtDeliverEndDate.Text.Trim());
                cookie.Values.Add("orderSource", dropOrderSource.SelectedValue);
                cookie.Values.Add("dealType", dropDealType.SelectedValue);
                cookie.Values.Add("deliver", dropDeliver.SelectedValue);
                cookie.Values.Add("clear", dropClear.SelectedValue);
                cookie.Values.Add("delete", dropDelete.SelectedValue);
                cookie.Values.Add("assureDeal", dropAssureDeal.SelectedValue);
                cookie.Values.Add("expressPrint", dropExpressPrint.SelectedValue);
                cookie.Values.Add("deliverPrint", dropDeliverPrint.SelectedValue);
                cookie.Values.Add("traner", dropTraner.SelectedValue);
                cookie.Values.Add("suggestion", dropOrderSuggestion.SelectedValue);
                cookie.Values.Add("expressBill", dropExpressBill.SelectedValue);
                cookie.Values.Add("gddh", txtgddh.Text.Trim());
                cookie.Values.Add("sj", txtsj.Text.Trim());
                cookie.Values.Add("address", txtaddress.Text.Trim());
                cookie.Values.Add("spdm", txtspdm.Text.Trim());
                cookie.Values.Add("pch", hdPCH.Value);
                if (ddlcusprint.Visible == true)
                {
                    cookie.Values.Add("dhdy", ddlcusprint.SelectedValue);
                }
                if (ddlinvoice.Visible == true)
                {
                    cookie.Values.Add("ddfp", ddlinvoice.SelectedValue);
                }
                if (ddl_lockmanager.Visible == true)
                {
                    cookie.Values.Add("lockmanager", ddl_lockmanager.SelectedValue);
                }
                this.Response.Cookies.Add(cookie);

            }
        }
    }
    #endregion 

    #region 重置查询条件
    private void ReadCookie()
    {
        HttpCookie cookie = Request.Cookies["Condition"];
        if (cookie != null)
        {
            txtOrderId.Text = cookie.Values["orderId"];
            chkCondition.Checked = bool.Parse(cookie.Values["chkCondition"]);
            txtDeliverBillId.Text = cookie.Values["deliverId"];
            txtCustomerId.Text = cookie.Values["customerId"];
            txtNickName.Text = cookie.Values["nickName"];
            txtReceiver.Text = cookie.Values["receiver"];
            txtOrderStartDate.Text = cookie.Values["orderStart"];
            txtOrderEndDate.Text = cookie.Values["orderEnd"];
            txtDeliverStartDate.Text = cookie.Values["deliverStart"];
            txtDeliverEndDate.Text = cookie.Values["deliverEnd"];

            dropOrderSource.SelectedValue = cookie.Values["orderSource"];
            dropDealType.SelectedValue = cookie.Values["dealType"];
            dropDeliver.SelectedValue = cookie.Values["deliver"];
            dropClear.SelectedValue = cookie.Values["clear"];
            dropDelete.SelectedValue = cookie.Values["delete"];
            dropAssureDeal.SelectedValue = cookie.Values["assureDeal"];
            dropExpressPrint.SelectedValue = cookie.Values["expressPrint"];
            dropDeliverPrint.SelectedValue = cookie.Values["deliverPrint"];
            dropTraner.SelectedValue = cookie.Values["traner"];
            dropOrderSuggestion.SelectedValue = cookie.Values["suggestion"];
            dropExpressBill.SelectedValue = cookie.Values["expressBill"];


            txtgddh.Text = cookie.Values["gddh"];
            txtsj.Text = cookie.Values["sj"];
            txtaddress.Text = cookie.Values["address"];
            txtspdm.Text = cookie.Values["spdm"];

            if (ddlcusprint.Visible == true)
            {
                ddlcusprint.SelectedValue = cookie.Values["dhdy"];
            }
            if (ddlinvoice.Visible == true)
            {
                ddlinvoice.SelectedValue = cookie.Values["ddfp"];
            }
            if (ddl_lockmanager.Visible == true)
            {
               ddl_lockmanager.SelectedValue = cookie.Values["lockmanager"];
           }
           dropPCH.Value = cookie.Values["pch"];

        }
    }
    #endregion

    #region 清空查询条件
    private void ClearCookie()
    {
        HttpCookie cookie = Request.Cookies["Condition"];
        if (cookie != null)
        {
            cookie.Expires = DateTime.Now.AddHours(-1);
            cookie.Values.Clear();
            Response.Cookies.Set(cookie);

            txtOrderId.Text = "";
            chkCondition.Checked = false;
            txtDeliverBillId.Text = "";
            txtCustomerId.Text = "";
            txtNickName.Text = "";
            txtReceiver.Text = "";
            txtOrderStartDate.Text = "";
            txtOrderEndDate.Text = "";
            txtDeliverStartDate.Text = "";
            txtDeliverEndDate.Text = "";

            dropOrderSource.SelectedValue = "-1";
            dropDealType.SelectedValue = "-1";
            dropDeliver.SelectedValue = "-1";
            dropClear.SelectedValue = "-1";
            dropDelete.SelectedValue = "-1";
            dropAssureDeal.SelectedValue = "-1";
            dropExpressPrint.SelectedValue = "-1";
            dropDeliverPrint.SelectedValue = "-1";
            dropTraner.SelectedValue = "-1";
            dropOrderSuggestion.SelectedValue = "-1";
            dropExpressBill.SelectedValue = "-1";

            ddlcusprint.SelectedValue = "-1";
            txtgddh.Text = "";
            txtsj.Text = "";
            txtaddress.Text = "";
            txtspdm.Text = "";

            ddlinvoice.SelectedValue = "-1";
            ddl_lockmanager.SelectedValue = "-1";
            dropPCH.Value = "";
            Bind();
        }
    }
    

    protected void clearCondition_Click(object sender, EventArgs e)
    {
        ClearCookie();
    }
    #endregion

    #region 更新打印状态位
    protected void btnPrintOrder_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("500100", "00020"))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('无权操作');document.getElementById('btnSearch').click()", true);
            return;
        }
        StringBuilder sbSql = new StringBuilder();
        string strOrderId = "";
        for (int i = 0; i < this.Selected.Count; i++)
        {
            if (i + 1 == this.Selected.Count)
            {
                strOrderId += this.Selected[i];
            }
            else
            {
                strOrderId += this.Selected[i] + "|";
            }
            sbSql.Append("update orderdoc set BYZD14=1,ORDER_PRINTCOUNT=ORDER_PRINTCOUNT+1 where order_id='");
            sbSql.Append(this.Selected[i]);
            sbSql.Append("'|");

        }
        if (strOrderId == "")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "alert('请选择需要打印的发货单！');document.getElementById('btnSearch').click()", true);
            return;
        }
        string stringSql = sbSql.ToString();
        char[] charArray = new char[] { '|' };
        string[] sqlCommandArray = stringSql.TrimEnd(charArray).Split(charArray);
        if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
        {
            string isRPT = ConfigurationManager.AppSettings["PrintMethod"];
            string sprinttype = "0";//默认打印时不显示界面
            if (ConfigurationManager.AppSettings["PrintType"] != null && ConfigurationManager.AppSettings["PrintType"] != "") sprinttype = ConfigurationManager.AppSettings["PrintType"];
            //By ltl add 打印
            string openurlstr = "";
            for (int i = 0; i < strOrderId.Split('|').Length; i++)
            {
                Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(strOrderId.Split('|')[i]);
                Model.V_CUSTOMER_AUTO customer = new BLL.V_CUSTOMER_AUTO().GetModel(order.ORDER_CUSTOMERCODE);
                if (customer.BYZD9 == "003" || customer.BYZD9 == "004" || customer.BYZD9 == "005")
                {
                    openurlstr += "window.open('../BillReport.aspx?PRINTER="+Share.UserValue(0)+"&DJBH=" + strOrderId.Split('|')[i] + "&ReportModule=FHGL/SDFHD&ReportName=PrintOrder2&PrintType=" + sprinttype + "');";
                }
                else
                {
                    openurlstr += "window.open('../BillReport.aspx?PRINTER=" + Share.UserValue(0) + "&DJBH=" + strOrderId.Split('|')[i] + "&ReportModule=FHGL/SDFHD&ReportName=PrintOrder&PrintType=" + sprinttype + "');";
                }
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUp", "" + openurlstr + ";document.getElementById('btnSearch').click()", true);

        }
    }
    #endregion

    #region 锁定/解锁
    protected void btnlock_Click(object sender, EventArgs e)
    {
        string orderid = "";
        string ret="";
        for (int i = 0; i < Selected.Count; i++)
        {
            orderid += Selected[i]+",";
        }
        if (orderid.Length < 1)
        {
            Share.Alert(this, "请选择要锁定的订单");
            return;
        }
        if (new BLL.ORDERDOC().SendLock(orderid, Share.UserValue(0), DateTime.Now, out ret))
        {
            if (ret.Length > 0)
            {
                Share.Alert(this, ret + "因此锁定没有成功，请去掉这些订单后重新锁定!");
                return;
            }
        }
        else
        {
            if (ret.Length > 0)
            {
                Share.Alert(this, ret + "因此锁定没有成功，请去掉这些订单后重新锁定!");
                return;
            }
        }
        Bind();
    }
    protected void btnUnlock_Click(object sender, EventArgs e)
    {
        string orderid = "";
        string ret = "";
        for (int i = 0; i < Selected.Count; i++)
        {
            orderid += Selected[i] + ",";
        }
        if (orderid.Length < 1)
        {
            Share.Alert(this, "请选择要解锁的订单");
            return;
        }
        if (new BLL.ORDERDOC().SendUnLock(orderid, Share.UserValue(0), DateTime.Now, out ret))
        {
            if (ret.Length > 0)
            {
                Share.Alert(this, ret + "因此解锁没有成功，请去掉这些订单后重新解锁!");
                return;
            }
        }
        else
        {
            if (ret.Length > 0)
            {
                Share.Alert(this, ret + "因此解锁没有成功，请去掉这些订单后重新解锁!");
                return;
            }
        }
        Bind();
    }
    #endregion

    #region 初始化锁定/解锁
    private void lockunlockSataus()
    {
        Model.SYSPARAM sys = new BLL.SYSPARAM().GetModel("010");
        if (sys != null)
        {
            if (sys.SP_PARAM1 == 1)
            {
                btnlock.Visible = true;
                btnUnlock.Visible = true;
                ddlcusprint.Visible = true;
                Label1.Visible = true;
                ddl_lockmanager.Visible = true;
                init_lockmanager();
                LockFlag = "1";
            }
            else
            {
                btnlock.Visible = false;
                btnUnlock.Visible = false;
                ddlcusprint.Visible = false;
                Label1.Visible = false;
                ddl_lockmanager.Visible = false;
                LockFlag = "0";
            }
        }
        else
        {
            btnlock.Visible = false;
            btnUnlock.Visible = false;
            ddlcusprint.Visible = false;
            Label1.Visible = false;
            ddl_lockmanager.Visible = false;
            LockFlag = "0";
        }
    }
    #endregion

    #region 初始化锁定人
    private void init_lockmanager()
    {
        DataSet ds = new BLL.USERS().getSameGroupManager(Share.UserValue(0), 0);
        if (ds != null)
        {
            ddl_lockmanager.DataSource = ds;
            ddl_lockmanager.DataTextField = "UUG_UserCode";
            ddl_lockmanager.DataValueField = "UUG_UserCode";
            ddl_lockmanager.DataBind();

            ListItem item = new ListItem();
            item.Value = "-1";
            item.Text = "请选择";
            ddl_lockmanager.Items.Insert(0, item);
        }
    }
    #endregion
    #region 初始化批次号
    private void init_PCH()
    {
        List<Model.PICI> list = new BLL.PICI().GetList(txtDeliverStartDate.Text.Trim(),txtDeliverEndDate.Text.Trim(), "PCH_ID");
        dropPCH.Items.Clear();
        dropPCH.Items.Add(new ListItem("请选择", "-1"));
        foreach (Model.PICI p in list)
        {
            dropPCH.Items.Add(new ListItem(p.PCH_ID,p.PCH_ID));
        }
        dropPCH.Value = hdPCH.Value;
    }
    #endregion

    #region 批次处理
    protected void btnStart_Click(object sender, EventArgs e)
    {
        Model.PICI pc = new BLL.PICI().GetModel(Share.UserValue(0), "PCH_ID");
        if (pc!= null)
        {
            Share.Alert(this, pc.PCH_ID + "批次尚未结束"); return;
        }
        else
        {
            string pch = BLL.Common.GetDM("500100");//生成新的批次号

            pc = new Model.PICI();
            pc.PCH_ID = pch;
            pc.PCH_STATUS=1;
            pc.PCH_CREATEDATE = DateTime.Now;
            pc.PCH_OPERATOR = Share.UserValue(0);
            if (new BLL.PICI().Add(pc) != null)
            {
                BLL.Common.ADDLSH("500100");
            }

        }
    }
    protected void btnEnd_Click(object sender, EventArgs e)
    {
        Model.PICI pc = new BLL.PICI().GetModel(Share.UserValue(0), "PCH_ID");
        if (pc != null)
        {
            pc.PCH_STATUS = 0;
            pc.PCH_ENDDATE = DateTime.Now;

            if (!new BLL.PICI().Update(pc))
            {
                Share.Alert(this, "操作失败");
            }
        }
    }


    #region ICallbackEventHandler 成员
    string result = "";

    string ICallbackEventHandler.GetCallbackResult()
    {
        return result;
    }

    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
    {
        Model.PICI pc = new BLL.PICI().GetModel(Share.UserValue(0), "PCH_ID");
        if (pc == null)
        {
            result = "请先开始一个批次|0";
        }
        else
        {
            List<Model.ORDERDOC> list = new BLL.ORDERDOC().GetList(pc.PCH_ID);
            result = list.Count.ToString() + "|1|" + pc.PCH_ID;
        }
    }

    #endregion
    #endregion
    private void BindColor(string productCode)
    {

        DataSet dstProductColor = new BLL.SHANGPIN().GetSPGG1(productCode);
        drpColor.DataSource = dstProductColor;
        drpColor.DataTextField = "ggmc";
        drpColor.DataValueField = "ggdm";
        drpColor.DataBind();
        drpColor.Items.Insert(0, new ListItem("", "-1"));
    }
    private void BindSize(string productCode)
    {
        DataSet dstProductSize = new BLL.SHANGPIN().GetSPGG2(productCode);
        drpSize.DataSource = dstProductSize;
        drpSize.DataTextField = "ggmc";
        drpSize.DataValueField = "ggdm";
        drpSize.DataBind();
        drpSize.Items.Insert(0, new ListItem("", "-1"));

    }
    protected void txtspdm_TextChanged(object sender, EventArgs e)
    {
        if (txtspdm.Text.Trim().Length > 0)
        {
            BindColor(txtspdm.Text.Trim());
            BindSize(txtspdm.Text.Trim());

        }
        else
        {
            drpColor.Items.Clear();
            drpSize.Items.Clear();

            drpColor.Items.Insert(0, new ListItem("", "-1"));
            drpSize.Items.Insert(0, new ListItem("", "-1"));
        }
    }
}
